package be.kuleuven.cs.mop.gui.dialogs;


import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;

import be.kuleuven.cs.mop.app.controllers.Controllers;
import be.kuleuven.cs.mop.domain.model.Project;
import be.kuleuven.cs.mop.gui.components.ActionButton;
import be.kuleuven.cs.mop.gui.components.TextInput;
import be.kuleuven.cs.mop.gui.util.SwingUtils;



/**
 * {@link ActionDialog} for the "Create Project" use case
 */
public class CreateProjectDialog extends ActionDialog {
	private static final long serialVersionUID = 1L;
	
	private final TextInput input = new TextInput();
	
	
	public CreateProjectDialog(final Frame parent, final Controllers controllers) {
		super(parent, "Create Project", controllers);
		final GridBagConstraints gbc = SwingUtils.getGBC();
		
		input.setToolTipText("Enter the description for the project");
		gbc.gridy	= 0;
		add(input, gbc);
		
		gbc.gridy	= 1;
		add(new ActionButton("Create", new Dimension(150, 32), this), gbc);
		
		display();
	}
	
	
	
	@Override
	protected void handle(final ActionEvent event) {
		try {
			final Project project =
				getControllers().getControllerProjects().createProject(input.read());
			log("Created project '%s'", project.getDescription());
			dispose();
		} catch (final Exception e) {
			log(e);
		}
	}
	
}